<script setup>

import { inject, ref, watch } from 'vue';

// func XXXX(msg: string)
const pros = defineProps({
  msg: {
    type: String,
    required: true,
  },
})




// 通过父组件, 修改msg, 回调函数/事件
// {'changed': fn, 'xxxx': fn}
// @changed=()=>{} @xxxx=()=>{}
// emit 事件总线 emit('changed', x, y, z)
// 调用事件总线，发送事件
// fn(args)
const emit = defineEmits(['update:msg'])

const inputText = ref(pros.msg)
watch(inputText, (v, ov)=> {
  emit("update:msg", v)
}, {immediate: true})


//
const username = inject('username')

</script>

<template>
  <div class="greetings">
    <h1 class="green">{{ msg }}</h1>
    <h3>
      You’ve successfully created a project with
      <a href="https://vite.dev/" target="_blank" rel="noopener">Vite</a> +
      <a href="https://vuejs.org/" target="_blank" rel="noopener">Vue 3</a>.
    </h3>
    <input style="width: 400px;" v-model="inputText" type="text">
    <hr>
    <span>username: {{ username }}</span>
  </div>
</template>

<style scoped>
h1 {
  font-weight: 500;
  font-size: 2.6rem;
  position: relative;
  top: -10px;
}

h3 {
  font-size: 1.2rem;
}

.greetings h1,
.greetings h3 {
  text-align: center;
}

@media (min-width: 1024px) {

  .greetings h1,
  .greetings h3 {
    text-align: left;
  }
}
</style>
